import Mock from 'mockjs'


Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/monitor/list`, 'post', () => {
    let projectArr = Mock.mock({
        'list|20': [
            {
                id: '@id',
                name: '@cname',
                'bpm|50-100':  100,
                'pressureBefore|100-120': 100,
                'pressureAfter|70-100': 70,
                'call|0-10': 0,
                "longitudeLng|110-120.6": 116.1,
                'longitudeLat|33-40.6': 39.1,
                'step|100-1000':  100,
                'temperature|35-37.1': 35.6,
                dateTime: '@datetime("yyyy-MM-dd HH:mm")',
                site: '@county(true)',
                imei: /\d{10}/,
                affiliation: '@ctitle()'
            }
        ]
    }).list
    return projectArr
})
Mock.Random.extend({
    phone: function () {
        var phonePrefixs = ['132', '135', '189'] // 自己写前缀哈
        return this.pick(phonePrefixs) + Mock.mock(/\d{8}/) //Number()
    }
})

Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/alarmRecord/list`, 'post', (request) => {
    let {page, pageSize} = JSON.parse(request.body),
        total = 134,
        list = [],
        num = parseInt(total/ pageSize) >= page ? pageSize : total - (pageSize * (page - 1));
    for(let item = 0; item < num; item++) {
        list.push(Mock.mock({
            id: '@id',
            name: '@cname',
            'alarmContent|0-5':  0,
            'phone': '@phone',
            'contact|1-2': [
                {
                    name: '@cname',
                    'phone': '@phone',
                }
            ],
            dateTime: '@datetime("yyyy-MM-dd HH:mm")',
            site: '@county(true)',
            handling: '@cparagraph(0|1)',
            "isHandling|1-2": true
        }))
    }
    return {
        list, total
    }
})


// 用户信息
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/user/info`, () => {
    return Mock.mock({
        info: {
            raelname: '@cname',
            gender: '@cword("男女")',
            phone: '@phone',
            birth: '@datetime("yyyy-MM-dd")',
            company: '@ctitle(5)',
        },
        'contact|1-3': [
            {
                name: '@cname',
                phone: '@phone',
            }
        ],
        equipment: {
            model: /[A-Z]-[0-9]{7}/,
            imei: /\d{5,10}/,
            bdTime: '@datetime("y-MM-dd HH:mm")'
        },
        'people|0-11': [
            {
                'relationship|1': [
                    "儿子",
                    "女儿",
                    "父亲",
                    "母亲",
                    "舅舅",
                    "舅妈",
                    "七大姑",
                    "八大姨",
                    "远房表姑妈",
                    "远房表表妹",
                ],
                phone: '@phone',
                bdTime: '@datetime("y-MM-dd HH:mm")'
            }
        ]
    })
})
// 数据变化趋势图
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/user/signChart`, () => {
    let blood = [], count = [], high = [], low = [], thedData = ['00:00','02:00','04:00','06:00','08:00','10:00','12:00','14:00','16:00','18:00','20:00','22:00'];
    // let countHead = ['00:00','02:00','04:00','06:00','08:00','10:00','12:00','14:00','16:00','18:00','20:00','22:00'];
    thedData.forEach(() => {
        blood.push(Mock.Random.integer(50, 100));
        low.push(Mock.Random.integer(50, 100));
        high.push(Mock.Random.integer(100, 200));
    });
    for (var i = 0; i < 5; i++) {
        count.push(Mock.Random.integer(400, 1000));
    }

    return {
        count, blood, high, low, thedData
    }
})
// 用户安全范围
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/user/safeRange`, () => {
    return Mock.mock({
        safeRange: {
            'heartRateStart|50-100': 70,
            'heartRateEnd|50-100': 70,
        },
        high: {
            'bloodStart|70-100': 70,
            'bloodEnd|50-70': 70,
        },
        low: {
            'bloodStart|70-100': 70,
            'bloodEnd|50-70': 70,
        },
        standard: {
            'bloodStart|70-100': 70,
            'bloodEnd|50-70': 70,
        },
        fence: '@ctitle(5)'
    })
})
// 行动轨迹
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/user/movement`, () => {
    return Mock.mock({
        'startLng|116-116.6': 116.4,
        'startLat|39-39.6': 39.9,
        'endLng|116-116.6': 116.4,
        'endLat|39-39.6': 39.9,
        'data|5-7': [
            {
                dateTime: '@datetime("yyyy-MM-dd HH:mm")',
                site: '@county(true)',
            }
        ]
    })
})
// 日志
Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/user/log`, (request) => {
    let {page, pageSize} = JSON.parse(request.body),
        total = 134,
        list = [],
        num = parseInt(total/ pageSize) >= page ? pageSize : total - (pageSize * (page - 1));
    for(let item = 0; item < num; item++) {
        list.push(Mock.mock({
            id: '@id',
            dateTime: '@datetime("yyyy-MM-dd HH:mm")',
            content: '@cparagraph(1, 3)',
        }))
    }
    return {
        list, total
    }
})
